home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / LINUX / PARPORT.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  15KB  |  394 lines

  1. /* $Id: parport.h,v 1.1 1998/05/17 10:57:52 andrea Exp andrea $ */
  2.  
  3. #ifndef _PARPORT_H_
  4. #define _PARPORT_H_
  5.  
  6. /* Start off with user-visible constants */
  7.  
  8. /* Maximum of 8 ports per machine */
  9. #define PARPORT_MAX  8 
  10.  
  11. /* Magic numbers */
  12. #define PARPORT_IRQ_NONE  -1
  13. #define PARPORT_DMA_NONE  -1
  14. #define PARPORT_IRQ_AUTO  -2
  15. #define PARPORT_DMA_AUTO  -2
  16. #define PARPORT_DISABLE   -2
  17. #define PARPORT_IRQ_PROBEONLY -3
  18.  
  19. #define PARPORT_CONTROL_STROBE    0x1
  20. #define PARPORT_CONTROL_AUTOFD    0x2
  21. #define PARPORT_CONTROL_INIT      0x4
  22. #define PARPORT_CONTROL_SELECT    0x8
  23. #define PARPORT_CONTROL_INTEN     0x10
  24. #define PARPORT_CONTROL_DIRECTION 0x20
  25.  
  26. #define PARPORT_STATUS_ERROR      0x8
  27. #define PARPORT_STATUS_SELECT     0x10
  28. #define PARPORT_STATUS_PAPEROUT   0x20
  29. #define PARPORT_STATUS_ACK        0x40
  30. #define PARPORT_STATUS_BUSY       0x80
  31.  
  32. /* Type classes for Plug-and-Play probe.  */
  33. typedef enum {
  34.     PARPORT_CLASS_LEGACY = 0,       /* Non-IEEE1284 device */
  35.     PARPORT_CLASS_PRINTER,
  36.     PARPORT_CLASS_MODEM,
  37.     PARPORT_CLASS_NET,
  38.     PARPORT_CLASS_HDC,              /* Hard disk controller */
  39.     PARPORT_CLASS_PCMCIA,
  40.     PARPORT_CLASS_MEDIA,            /* Multimedia device */
  41.     PARPORT_CLASS_FDC,              /* Floppy disk controller */
  42.     PARPORT_CLASS_PORTS,
  43.     PARPORT_CLASS_SCANNER,
  44.     PARPORT_CLASS_DIGCAM,
  45.     PARPORT_CLASS_OTHER,            /* Anything else */
  46.     PARPORT_CLASS_UNSPEC            /* No CLS field in ID */
  47. } parport_device_class;
  48.  
  49. /* The "modes" entry in parport is a bit field representing the following
  50.  * modes.
  51.  * Note that PARPORT_MODE_PCECPEPP is for the SMC EPP+ECP mode which is NOT
  52.  * 100% compatible with EPP.
  53.  */
  54. #define PARPORT_MODE_PCSPP            0x0001
  55. #define PARPORT_MODE_PCPS2        0x0002
  56. #define PARPORT_MODE_PCEPP        0x0004
  57. #define PARPORT_MODE_PCECP        0x0008
  58. #define PARPORT_MODE_PCECPEPP        0x0010
  59. #define PARPORT_MODE_PCECR        0x0020  /* ECR Register Exists */
  60. #define PARPORT_MODE_PCECPPS2        0x0040
  61.  
  62. /* The rest is for the kernel only */
  63. #ifdef __KERNEL__
  64.  
  65. #include <asm/system.h>
  66. #include <asm/ptrace.h>
  67. #include <asm/spinlock.h>
  68. #include <linux/proc_fs.h>
  69. #include <linux/config.h>
  70.  
  71. #define PARPORT_NEED_GENERIC_OPS
  72.  
  73. /* Define this later. */
  74. struct parport;
  75.  
  76. struct pc_parport_state {
  77.     unsigned int ctr;
  78.     unsigned int ecr;
  79. };
  80.  
  81. struct parport_state {
  82.     union {
  83.         struct pc_parport_state pc;
  84.         /* ARC has no state. */
  85.         /* AX uses same state information as PC */
  86.         void *misc; 
  87.     } u;
  88. };
  89.  
  90. struct parport_operations {
  91.     void (*write_data)(struct parport *, unsigned char);
  92.     unsigned char (*read_data)(struct parport *);
  93.     void (*write_control)(struct parport *, unsigned char);
  94.     unsigned char (*read_control)(struct parport *);
  95.     unsigned char (*frob_control)(struct parport *, unsigned char mask, unsigned char val);
  96.     void (*write_econtrol)(struct parport *, unsigned char);
  97.     unsigned char (*read_econtrol)(struct parport *);
  98.     unsigned char (*frob_econtrol)(struct parport *, unsigned char mask, unsigned char val);
  99.     void (*write_status)(struct parport *, unsigned char);
  100.     unsigned char (*read_status)(struct parport *);
  101.     void (*write_fifo)(struct parport *, unsigned char);
  102.     unsigned char (*read_fifo)(struct parport *);
  103.  
  104.     void (*change_mode)(struct parport *, int);
  105.  
  106.     void (*release_resources)(struct parport *);
  107.     int (*claim_resources)(struct parport *);
  108.  
  109.     void (*epp_write_data)(struct parport *, unsigned char);
  110.     unsigned char (*epp_read_data)(struct parport *);
  111.     void (*epp_write_addr)(struct parport *, unsigned char);
  112.     unsigned char (*epp_read_addr)(struct parport *);
  113.     int (*epp_check_timeout)(struct parport *);
  114.     size_t (*epp_write_block)(struct parport *, void *, size_t);
  115.     size_t (*epp_read_block)(struct parport *, void *, size_t);
  116.  
  117.     int (*ecp_write_block)(struct parport *, void *, size_t, void (*fn)(struct parport *, void *, size_t), void *);
  118.     int (*ecp_read_block)(struct parport *, void *, size_t, void (*fn)(struct parport *, void *, size_t), void *);
  119.  
  120.     void (*init_state)(struct parport_state *);
  121.     void (*save_state)(struct parport *, struct parport_state *);
  122.     void (*restore_state)(struct parport *, struct parport_state *);
  123.  
  124.     void (*enable_irq)(struct parport *);
  125.     void (*disable_irq)(struct parport *);
  126.     void (*interrupt)(int, void *, struct pt_regs *);
  127.  
  128.     void (*inc_use_count)(void);
  129.     void (*dec_use_count)(void);
  130.     void (*fill_inode)(struct inode *inode, int fill);
  131. };
  132.  
  133. struct parport_device_info {
  134.     parport_device_class class;
  135.     const char *class_name;
  136.     const char *mfr;
  137.     const char *model;
  138.     const char *cmdset;
  139.     const char *description;
  140. };
  141.  
  142. /* Each device can have two callback functions:
  143.  *  1) a preemption function, called by the resource manager to request
  144.  *     that the driver relinquish control of the port.  The driver should
  145.  *     return zero if it agrees to release the port, and nonzero if it 
  146.  *     refuses.  Do not call parport_release() - the kernel will do this
  147.  *     implicitly.
  148.  *
  149.  *  2) a wake-up function, called by the resource manager to tell drivers
  150.  *     that the port is available to be claimed.  If a driver wants to use
  151.  *     the port, it should call parport_claim() here.
  152.  */
  153.  
  154. /* A parallel port device */
  155. struct pardevice {
  156.     const char *name;
  157.     struct parport *port;
  158.     int (*preempt)(void *);
  159.     void (*wakeup)(void *);
  160.     void *private;
  161.     void (*irq_func)(int, void *, struct pt_regs *);
  162.     unsigned int flags;
  163.     struct pardevice *next;
  164.     struct pardevice *prev;
  165.     struct parport_state *state;     /* saved status over preemption */
  166.     struct wait_queue *wait_q;
  167.     unsigned long int time;
  168.     unsigned long int timeslice;
  169.     unsigned int waiting;
  170.     struct pardevice *waitprev;
  171.     struct pardevice *waitnext;
  172. };
  173.  
  174. /* Directory information for the /proc interface */
  175. struct parport_dir {
  176.     struct proc_dir_entry *entry;    /* Directory /proc/parport/X     */
  177.     struct proc_dir_entry *irq;    /*        .../irq           */
  178.     struct proc_dir_entry *devices;  /*        .../devices       */
  179.     struct proc_dir_entry *hardware; /*        .../hardware      */
  180.     struct proc_dir_entry *probe;     /*        .../autoprobe      */
  181.     char name[4];
  182. };
  183.  
  184. /* A parallel port */
  185. struct parport {
  186.     unsigned long base;    /* base address */
  187.     unsigned int size;    /* IO extent */
  188.     const char *name;
  189.     int irq;        /* interrupt (or -1 for none) */
  190.     int dma;
  191.     unsigned int modes;
  192.  
  193.     struct pardevice *devices;
  194.     struct pardevice *cad;    /* port owner */
  195.  
  196.     struct pardevice *waithead;
  197.     struct pardevice *waittail;
  198.     
  199.     struct parport *next;
  200.     unsigned int flags;
  201.  
  202.     struct parport_dir pdir;
  203.     struct parport_device_info probe_info; 
  204.  
  205.     struct parport_operations *ops;
  206.     void *private_data;     /* for lowlevel driver */
  207.  
  208.     int number;        /* port index - the `n' in `parportn' */
  209.     spinlock_t pardevice_lock;
  210.     spinlock_t waitlist_lock;
  211.     rwlock_t cad_lock;
  212. };
  213.  
  214. /* parport_register_port registers a new parallel port at the given address (if
  215.  * one does not already exist) and returns a pointer to it.  This entails
  216.  * claiming the I/O region, IRQ and DMA.
  217.  * NULL is returned if initialisation fails. 
  218.  */
  219. struct parport *parport_register_port(unsigned long base, int irq, int dma,
  220.                       struct parport_operations *ops);
  221.  
  222. /* Unregister a port. */
  223. extern void parport_unregister_port(struct parport *port);
  224.  
  225. /* parport_in_use returns nonzero if there are devices attached to a port. */
  226. #define parport_in_use(x)  ((x)->devices != NULL)
  227.  
  228. /* Put a parallel port to sleep; release its hardware resources.  Only possible
  229.  * if no devices are registered.  */
  230. extern void parport_quiesce(struct parport *);
  231.  
  232. /* parport_enumerate returns a pointer to the linked list of all the ports
  233.  * in this machine.
  234.  */
  235. struct parport *parport_enumerate(void);
  236.  
  237. /* parport_register_device declares that a device is connected to a port, and 
  238.  * tells the kernel all it needs to know.  
  239.  * pf is the preemption function (may be NULL for no callback)
  240.  * kf is the wake-up function (may be NULL for no callback)
  241.  * irq_func is the interrupt handler (may be NULL for no interrupts)
  242.  * handle is a user pointer that gets handed to callback functions. 
  243.  */
  244. struct pardevice *parport_register_device(struct parport *port, 
  245.               const char *name,
  246.               int (*pf)(void *), void (*kf)(void *),
  247.               void (*irq_func)(int, void *, struct pt_regs *), 
  248.               int flags, void *handle);
  249.  
  250. /* parport_unregister unlinks a device from the chain. */
  251. extern void parport_unregister_device(struct pardevice *dev);
  252.  
  253. /* parport_claim tries to gain ownership of the port for a particular driver.
  254.  * This may fail (return non-zero) if another driver is busy.  If this
  255.  * driver has registered an interrupt handler, it will be enabled. 
  256.  */
  257. extern int parport_claim(struct pardevice *dev);
  258.  
  259. /* parport_claim_or_block is the same, but sleeps if the port cannot be 
  260.    claimed.  Return value is 1 if it slept, 0 normally and -errno on error.  */
  261. extern int parport_claim_or_block(struct pardevice *dev);
  262.  
  263. /* parport_release reverses a previous parport_claim.  This can never fail, 
  264.  * though the effects are undefined (except that they are bad) if you didn't
  265.  * previously own the port.  Once you have released the port you should make
  266.  * sure that neither your code nor the hardware on the port tries to initiate
  267.  * any communication without first re-claiming the port.
  268.  * If you mess with the port state (enabling ECP for example) you should
  269.  * clean up before releasing the port. 
  270.  */
  271.  
  272. extern void parport_release(struct pardevice *dev);
  273.  
  274. /* parport_yield relinquishes the port if it would be helpful to other
  275.  * drivers.  The return value is the same as for parport_claim.
  276.  */
  277. extern __inline__ int parport_yield(struct pardevice *dev)
  278. {
  279.     unsigned long int timeslip = (jiffies - dev->time);
  280.     if ((dev->port->waithead == NULL) || (timeslip < dev->timeslice))
  281.         return 0;
  282.     parport_release(dev);
  283.     return parport_claim(dev);
  284. }
  285.  
  286. /* parport_yield_blocking is the same but uses parport_claim_or_block
  287.  * instead of parport_claim.
  288.  */
  289. extern __inline__ int parport_yield_blocking(struct pardevice *dev)
  290. {
  291.     unsigned long int timeslip = (jiffies - dev->time);
  292.     if ((dev->port->waithead == NULL) || (timeslip < dev->timeslice))
  293.         return 0;
  294.     parport_release(dev);
  295.     return parport_claim_or_block(dev);
  296. }
  297.  
  298. /*
  299.  * Lowlevel drivers _can_ call this support function to handle irqs.
  300.  */
  301. extern __inline__ void parport_generic_irq(int irq, struct parport *port,
  302.                        struct pt_regs *regs)
  303. {
  304.     read_lock(&port->cad_lock);
  305.     if (!port->cad)
  306.         goto out_unlock;
  307.     if (port->cad->irq_func)
  308.         port->cad->irq_func(irq, port->cad->private, regs);
  309.     else
  310.         printk(KERN_ERR "%s: irq%d happened with irq_func NULL "
  311.                "with %s as cad!\n", port->name, irq, port->cad->name);
  312.  out_unlock:
  313.     read_unlock(&port->cad_lock);
  314. }
  315.  
  316. /* Flags used to identify what a device does. */
  317. #define PARPORT_DEV_TRAN        0    /* WARNING !! DEPRECATED !! */
  318. #define PARPORT_DEV_LURK        (1<<0)    /* WARNING !! DEPRECATED !! */
  319. #define PARPORT_DEV_EXCL        (1<<1)    /* Need exclusive access. */
  320.  
  321. #define PARPORT_FLAG_COMA        (1<<0)
  322. #define PARPORT_FLAG_EXCL        (1<<1)    /* EXCL driver registered. */
  323.  
  324. extern void parport_parse_irqs(int, const char *[], int irqval[]);
  325. extern int parport_ieee1284_nibble_mode_ok(struct parport *, unsigned char);
  326. extern int parport_wait_peripheral(struct parport *, unsigned char, unsigned
  327.                    char);
  328.  
  329. /* Prototypes from parport_procfs */
  330. extern int parport_proc_init(void);
  331. extern void parport_proc_cleanup(void);
  332. extern int parport_proc_register(struct parport *pp);
  333. extern int parport_proc_unregister(struct parport *pp);
  334.  
  335. extern void dec_parport_count(void);
  336. extern void inc_parport_count(void);
  337.  
  338. extern int parport_probe(struct parport *port, char *buffer, int len);
  339. extern void parport_probe_one(struct parport *port);
  340. extern void (*parport_probe_hook)(struct parport *port);
  341.  
  342. /* If PC hardware is the only type supported, we can optimise a bit.  */
  343. #if (defined(CONFIG_PARPORT_PC) || defined(CONFIG_PARPORT_PC_MODULE)) && !(defined(CONFIG_PARPORT_AX) || defined(CONFIG_PARPORT_AX_MODULE)) && !(defined(CONFIG_PARPORT_ARC) || defined(CONFIG_PARPORT_ARC_MODULE)) && !defined(CONFIG_PARPORT_OTHER)
  344. #undef PARPORT_NEED_GENERIC_OPS
  345. #include <linux/parport_pc.h>
  346. #define parport_write_data(p,x)            parport_pc_write_data(p,x)
  347. #define parport_read_data(p)               parport_pc_read_data(p)
  348. #define parport_write_control(p,x)         parport_pc_write_control(p,x)
  349. #define parport_read_control(p)            parport_pc_read_control(p)
  350. #define parport_frob_control(p,m,v)        parport_pc_frob_control(p,m,v)
  351. #define parport_write_econtrol(p,x)        parport_pc_write_econtrol(p,x)
  352. #define parport_read_econtrol(p)           parport_pc_read_econtrol(p)
  353. #define parport_frob_econtrol(p,m,v)       parport_pc_frob_econtrol(p,m,v)
  354. #define parport_write_status(p,v)          parport_pc_write_status(p,v)
  355. #define parport_read_status(p)             parport_pc_read_status(p)
  356. #define parport_write_fifo(p,v)            parport_pc_write_fifo(p,v)
  357. #define parport_read_fifo(p)               parport_pc_read_fifo(p)
  358. #define parport_change_mode(p,m)           parport_pc_change_mode(p,m)
  359. #define parport_release_resources(p)       parport_pc_release_resources(p)
  360. #define parport_claim_resources(p)         parport_pc_claim_resources(p)
  361. #define parport_epp_write_data(p,x)        parport_pc_write_epp(p,x)
  362. #define parport_epp_read_data(p)           parport_pc_read_epp(p)
  363. #define parport_epp_write_addr(p,x)        parport_pc_write_epp_addr(p,x)
  364. #define parport_epp_read_addr(p)           parport_pc_read_epp_addr(p)
  365. #define parport_epp_check_timeout(p)       parport_pc_check_epp_timeout(p)
  366. #endif
  367.  
  368. #ifdef PARPORT_NEED_GENERIC_OPS
  369. /* Generic operations vector through the dispatch table. */
  370. #define parport_write_data(p,x)            (p)->ops->write_data(p,x)
  371. #define parport_read_data(p)               (p)->ops->read_data(p)
  372. #define parport_write_control(p,x)         (p)->ops->write_control(p,x)
  373. #define parport_read_control(p)            (p)->ops->read_control(p)
  374. #define parport_frob_control(p,m,v)        (p)->ops->frob_control(p,m,v)
  375. #define parport_write_econtrol(p,x)        (p)->ops->write_econtrol(p,x)
  376. #define parport_read_econtrol(p)           (p)->ops->read_econtrol(p)
  377. #define parport_frob_econtrol(p,m,v)       (p)->ops->frob_econtrol(p,m,v)
  378. #define parport_write_status(p,v)          (p)->ops->write_status(p,v)
  379. #define parport_read_status(p)             (p)->ops->read_status(p)
  380. #define parport_write_fifo(p,v)            (p)->ops->write_fifo(p,v)
  381. #define parport_read_fifo(p)               (p)->ops->read_fifo(p)
  382. #define parport_change_mode(p,m)           (p)->ops->change_mode(p,m)
  383. #define parport_release_resources(p)       (p)->ops->release_resources(p)
  384. #define parport_claim_resources(p)         (p)->ops->claim_resources(p)
  385. #define parport_epp_write_data(p,x)        (p)->ops->epp_write_data(p,x)
  386. #define parport_epp_read_data(p)           (p)->ops->epp_read_data(p)
  387. #define parport_epp_write_addr(p,x)        (p)->ops->epp_write_addr(p,x)
  388. #define parport_epp_read_addr(p)           (p)->ops->epp_read_addr(p)
  389. #define parport_epp_check_timeout(p)       (p)->ops->epp_check_timeout(p)
  390. #endif
  391.  
  392. #endif /* __KERNEL__ */
  393. #endif /* _PARPORT_H_ */
  394.